package com.sxfq.loansupermarket.backsystem.modular.basicData.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.sxfq.loansupermarket.backsystem.core.util.StringUtil;
import com.sxfq.loansupermarket.backsystem.modular.base.SqlMapper;
import com.sxfq.loansupermarket.backsystem.modular.basicData.dao.ReservationsProjectDao;
import com.sxfq.loansupermarket.backsystem.modular.basicData.entity.ReservationsProjectInfo;
import com.sxfq.loansupermarket.backsystem.modular.basicData.entity.SearchReservationsProjectInfo;
import com.sxfq.loansupermarket.backsystem.modular.basicData.service.IReservationsProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class ReservationsProjectServiceImpl implements IReservationsProjectService {

    @Autowired
    private ReservationsProjectDao dao;

    @Autowired
    private SqlMapper sqlMapper;

    @Override
    public List<ReservationsProjectInfo> selectPageListByQueryGetMap(Page<ReservationsProjectInfo> page, SearchReservationsProjectInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getReservationsProject())) {
            params.put("reservationsProject", searchInfo.getReservationsProject());
        }
        return dao.getQueryPage(page, params);
    }

    public ReservationsProjectInfo selectOneById(String reservationsProjectId) {
        String sql = "select * from reservations_project_info where id= '" + reservationsProjectId + "'";
        ReservationsProjectInfo info = sqlMapper.selectOne(sql, ReservationsProjectInfo.class);
        return info;
    }

    public int insert(ReservationsProjectInfo info) {
        String sql = "INSERT INTO `reservations_project_info` (`reservations_project`, `remarks`, `num`) VALUES" +
                "('" + info.getReservationsProject().trim() + "','" + info.getRemarks().trim() + "'," + info.getNum() + ");";
        return sqlMapper.insert(sql);
    }


    @Transactional
    public void delete(String id) {
        String sql = "delete from reservations_project_info  where id = '" + id + "'";
        sqlMapper.delete(sql);
    }

    public int update(ReservationsProjectInfo info) {
        return dao.updateById(info);
    }

    public List<Map<String, Object>> list() {
        String sql = "select id, reservations_project from reservations_project_info order by  num asc;";
        return sqlMapper.selectList(sql);
    }
}
